/**
 * 作者: clz
 * 日期: 2025-04-08 19:57:14
 * 备注: 用户联盟信息
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserUnion;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserUnionModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 用户id
	protected long unionId; // 公会id
	protected int post; // 职位类型 (0成员，1会长，2副会长，3长老)
	protected long leaveTime; // 退出公会时间
	protected int contribution; // 总贡献
	protected int dayContribution; // 今日贡献
	protected long tempEndTime; // 临时成员结束时间
	protected int isFreeCreate; // vip2是否免费创建
	protected int businessNum; // 运输中心当前次数 (0)
	protected long businessTime; // 运输中心恢复时间 (当前时间)
	protected int businessDayNum; // 运输中心今日次数
	protected int businessTotalNum; // 运输中心总次数
	protected String donateNum = ""; // 捐献次数 ({type:num})
	protected String donateProgressReward = ""; // 捐献进度领取奖励 (1;2;3)
	protected long resetTime; // 重置时间
	protected String actChargeReward = ""; // 限时充值活动领取情况
	protected int actChargePrice; // 限时充值活动充值金额
	protected long actChargeTime; // 限时充值活动时间
	protected int discountShopPrice; // 折扣商店砍价金额 (0:未砍价 !=0:已砍价)
	protected byte isDiscountShopBuy; // 折扣商店是否已购买 (0:未购买 1:已购买)
	protected int bossFreeNum; // 远征击打次数
	protected int bossBuyNum; // 远征购买次数
	protected int bossAddPowerNum; // 远征加成战力次数

	public void reset() {
	}

	protected String getKey() {
		return "UserUnion." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_union"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入库
	 */
	public JsonObject updateNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE_NOW, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 用户id
		obj.put("unionId", unionId); // 公会id
		obj.put("post", post); // 职位类型 (0成员，1会长，2副会长，3长老)
		obj.put("leaveTime", leaveTime); // 退出公会时间
		obj.put("contribution", contribution); // 总贡献
		obj.put("dayContribution", dayContribution); // 今日贡献
		obj.put("tempEndTime", tempEndTime); // 临时成员结束时间
		obj.put("isFreeCreate", isFreeCreate); // vip2是否免费创建
		obj.put("businessNum", businessNum); // 运输中心当前次数 (0)
		obj.put("businessTime", businessTime); // 运输中心恢复时间 (当前时间)
		obj.put("businessDayNum", businessDayNum); // 运输中心今日次数
		obj.put("businessTotalNum", businessTotalNum); // 运输中心总次数
		obj.put("donateNum", donateNum); // 捐献次数 ({type:num})
		obj.put("donateProgressReward", donateProgressReward); // 捐献进度领取奖励 (1;2;3)
		obj.put("resetTime", resetTime); // 重置时间
		obj.put("actChargeReward", actChargeReward); // 限时充值活动领取情况
		obj.put("actChargePrice", actChargePrice); // 限时充值活动充值金额
		obj.put("actChargeTime", actChargeTime); // 限时充值活动时间
		obj.put("discountShopPrice", discountShopPrice); // 折扣商店砍价金额 (0:未砍价 !=0:已砍价)
		obj.put("isDiscountShopBuy", isDiscountShopBuy); // 折扣商店是否已购买 (0:未购买 1:已购买)
		obj.put("bossFreeNum", bossFreeNum); // 远征免费次数
		obj.put("bossBuyNum", bossBuyNum); // 远征购买次数
		obj.put("bossAddPowerNum", bossAddPowerNum); // 远征加成战力次数
		return obj;
	}

	public PBUserUnion.Builder takeInitBuilder() {
		PBUserUnion.Builder sb = PBUserUnion.newBuilder();
		if (post != 0) {
			sb.setPost(post);
		}
		if (leaveTime != 0) {
			sb.setLeaveTime(leaveTime);
		}
		if (contribution != 0) {
			sb.setContribution(contribution);
		}
		if (dayContribution != 0) {
			sb.setDayContribution(dayContribution);
		}
		if (tempEndTime != 0) {
			sb.setTempEndTime(tempEndTime);
		}
		if (isFreeCreate != 0) {
			sb.setIsFreeCreate(isFreeCreate);
		}
		if (businessNum != 0) {
			sb.setBusinessNum(businessNum);
		}
		if (businessTime != 0) {
			sb.setBusinessTime(businessTime);
		}
		if (businessDayNum != 0) {
			sb.setBusinessDayNum(businessDayNum);
		}
		if (businessTotalNum != 0) {
			sb.setBusinessTotalNum(businessTotalNum);
		}
		if (!donateNum.isEmpty()) {
			sb.setDonateNum(donateNum);
		}
		if (!donateProgressReward.isEmpty()) {
			sb.setDonateProgressReward(donateProgressReward);
		}
		if (!actChargeReward.isEmpty()) {
			sb.setActChargeReward(actChargeReward);
		}
		if (discountShopPrice != 0) {
			sb.setDiscountShopPrice(discountShopPrice);
		}
		if (isDiscountShopBuy != 0) {
			sb.setIsDiscountShopBuy(isDiscountShopBuy);
		}
		if (bossFreeNum != 0) {
			sb.setBossFreeNum(bossFreeNum);
		}
		if (bossBuyNum != 0) {
			sb.setBossBuyNum(bossBuyNum);
		}
		if (bossAddPowerNum != 0) {
			sb.setBossAddPowerNum(bossAddPowerNum);
		}
		return sb;
	}

	public PBUserUnion.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserUnion.Builder sb = PBUserUnion.newBuilder();
		if (isFieldUpdate("post")) {
			sb.setPost(post);
		}
		if (isFieldUpdate("leaveTime")) {
			sb.setLeaveTime(leaveTime);
		}
		if (isFieldUpdate("contribution")) {
			sb.setContribution(contribution);
		}
		if (isFieldUpdate("dayContribution")) {
			sb.setDayContribution(dayContribution);
		}
		if (isFieldUpdate("tempEndTime")) {
			sb.setTempEndTime(tempEndTime);
		}
		if (isFieldUpdate("isFreeCreate")) {
			sb.setIsFreeCreate(isFreeCreate);
		}
		if (isFieldUpdate("businessNum")) {
			sb.setBusinessNum(businessNum);
		}
		if (isFieldUpdate("businessTime")) {
			sb.setBusinessTime(businessTime);
		}
		if (isFieldUpdate("businessDayNum")) {
			sb.setBusinessDayNum(businessDayNum);
		}
		if (isFieldUpdate("businessTotalNum")) {
			sb.setBusinessTotalNum(businessTotalNum);
		}
		if (isFieldUpdate("donateNum")) {
			sb.setDonateNum(donateNum);
		}
		if (isFieldUpdate("donateProgressReward")) {
			sb.setDonateProgressReward(donateProgressReward);
		}
		if (isFieldUpdate("actChargeReward")) {
			sb.setActChargeReward(actChargeReward);
		}
		if (isFieldUpdate("discountShopPrice")) {
			sb.setDiscountShopPrice(discountShopPrice);
		}
		if (isFieldUpdate("isDiscountShopBuy")) {
			sb.setIsDiscountShopBuy(isDiscountShopBuy);
		}
		if (isFieldUpdate("bossFreeNum")) {
			sb.setBossFreeNum(bossFreeNum);
		}
		if (isFieldUpdate("bossBuyNum")) {
			sb.setBossBuyNum(bossBuyNum);
		}
		if (isFieldUpdate("bossAddPowerNum")) {
			sb.setBossAddPowerNum(bossAddPowerNum);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUnionId() {
		return unionId;
	}

	public void putUnionId(long unionId) {
		if (this.unionId != unionId) {
			this.unionId = unionId;
			updateRedisHashField(getKey(), "unionId", this.unionId);
		}
	}

	public void addUnionId(long value) {
		this.unionId += value;
		updateRedisHashField(getKey(), "unionId", this.unionId);
	}

	public int getPost() {
		return post;
	}

	public void putPost(int post) {
		if (this.post != post) {
			this.post = post;
			updateRedisHashField(getKey(), "post", this.post);
		}
	}

	public void addPost(int value) {
		this.post += value;
		updateRedisHashField(getKey(), "post", this.post);
	}

	public long getLeaveTime() {
		return leaveTime;
	}

	public void putLeaveTime(long leaveTime) {
		if (this.leaveTime != leaveTime) {
			this.leaveTime = leaveTime;
			updateRedisHashField(getKey(), "leaveTime", this.leaveTime);
		}
	}

	public void addLeaveTime(long value) {
		this.leaveTime += value;
		updateRedisHashField(getKey(), "leaveTime", this.leaveTime);
	}

	public int getContribution() {
		return contribution;
	}

	public void putContribution(int contribution) {
		if (this.contribution != contribution) {
			this.contribution = contribution;
			updateRedisHashField(getKey(), "contribution", this.contribution);
		}
	}

	public void addContribution(int value) {
		this.contribution += value;
		updateRedisHashField(getKey(), "contribution", this.contribution);
	}

	public int getDayContribution() {
		return dayContribution;
	}

	public void putDayContribution(int dayContribution) {
		if (this.dayContribution != dayContribution) {
			this.dayContribution = dayContribution;
			updateRedisHashField(getKey(), "dayContribution", this.dayContribution);
		}
	}

	public void addDayContribution(int value) {
		this.dayContribution += value;
		updateRedisHashField(getKey(), "dayContribution", this.dayContribution);
	}

	public long getTempEndTime() {
		return tempEndTime;
	}

	public void putTempEndTime(long tempEndTime) {
		if (this.tempEndTime != tempEndTime) {
			this.tempEndTime = tempEndTime;
			updateRedisHashField(getKey(), "tempEndTime", this.tempEndTime);
		}
	}

	public void addTempEndTime(long value) {
		this.tempEndTime += value;
		updateRedisHashField(getKey(), "tempEndTime", this.tempEndTime);
	}

	public int getIsFreeCreate() {
		return isFreeCreate;
	}

	public void putIsFreeCreate(int isFreeCreate) {
		if (this.isFreeCreate != isFreeCreate) {
			this.isFreeCreate = isFreeCreate;
			updateRedisHashField(getKey(), "isFreeCreate", this.isFreeCreate);
		}
	}

	public void addIsFreeCreate(int value) {
		this.isFreeCreate += value;
		updateRedisHashField(getKey(), "isFreeCreate", this.isFreeCreate);
	}

	public int getBusinessNum() {
		return businessNum;
	}

	public void putBusinessNum(int businessNum) {
		if (this.businessNum != businessNum) {
			this.businessNum = businessNum;
			updateRedisHashField(getKey(), "businessNum", this.businessNum);
		}
	}

	public void addBusinessNum(int value) {
		this.businessNum += value;
		updateRedisHashField(getKey(), "businessNum", this.businessNum);
	}

	public long getBusinessTime() {
		return businessTime;
	}

	public void putBusinessTime(long businessTime) {
		if (this.businessTime != businessTime) {
			this.businessTime = businessTime;
			updateRedisHashField(getKey(), "businessTime", this.businessTime);
		}
	}

	public void addBusinessTime(long value) {
		this.businessTime += value;
		updateRedisHashField(getKey(), "businessTime", this.businessTime);
	}

	public int getBusinessDayNum() {
		return businessDayNum;
	}

	public void putBusinessDayNum(int businessDayNum) {
		if (this.businessDayNum != businessDayNum) {
			this.businessDayNum = businessDayNum;
			updateRedisHashField(getKey(), "businessDayNum", this.businessDayNum);
		}
	}

	public void addBusinessDayNum(int value) {
		this.businessDayNum += value;
		updateRedisHashField(getKey(), "businessDayNum", this.businessDayNum);
	}

	public int getBusinessTotalNum() {
		return businessTotalNum;
	}

	public void putBusinessTotalNum(int businessTotalNum) {
		if (this.businessTotalNum != businessTotalNum) {
			this.businessTotalNum = businessTotalNum;
			updateRedisHashField(getKey(), "businessTotalNum", this.businessTotalNum);
		}
	}

	public void addBusinessTotalNum(int value) {
		this.businessTotalNum += value;
		updateRedisHashField(getKey(), "businessTotalNum", this.businessTotalNum);
	}

	public String getDonateNum() {
		return donateNum;
	}

	public void putDonateNum(String donateNum) {
		if (!this.donateNum.equals(donateNum)) {
			this.donateNum = donateNum;
			updateRedisHashField(getKey(), "donateNum", this.donateNum);
		}
	}

	public String getDonateProgressReward() {
		return donateProgressReward;
	}

	public void putDonateProgressReward(String donateProgressReward) {
		if (!this.donateProgressReward.equals(donateProgressReward)) {
			this.donateProgressReward = donateProgressReward;
			updateRedisHashField(getKey(), "donateProgressReward", this.donateProgressReward);
		}
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

	public String getActChargeReward() {
		return actChargeReward;
	}

	public void putActChargeReward(String actChargeReward) {
		if (!this.actChargeReward.equals(actChargeReward)) {
			this.actChargeReward = actChargeReward;
			updateRedisHashField(getKey(), "actChargeReward", this.actChargeReward);
		}
	}

	public int getActChargePrice() {
		return actChargePrice;
	}

	public void putActChargePrice(int actChargePrice) {
		if (this.actChargePrice != actChargePrice) {
			this.actChargePrice = actChargePrice;
			updateRedisHashField(getKey(), "actChargePrice", this.actChargePrice);
		}
	}

	public void addActChargePrice(int value) {
		this.actChargePrice += value;
		updateRedisHashField(getKey(), "actChargePrice", this.actChargePrice);
	}

	public long getActChargeTime() {
		return actChargeTime;
	}

	public void putActChargeTime(long actChargeTime) {
		if (this.actChargeTime != actChargeTime) {
			this.actChargeTime = actChargeTime;
			updateRedisHashField(getKey(), "actChargeTime", this.actChargeTime);
		}
	}

	public void addActChargeTime(long value) {
		this.actChargeTime += value;
		updateRedisHashField(getKey(), "actChargeTime", this.actChargeTime);
	}

	public int getDiscountShopPrice() {
		return discountShopPrice;
	}

	public void putDiscountShopPrice(int discountShopPrice) {
		if (this.discountShopPrice != discountShopPrice) {
			this.discountShopPrice = discountShopPrice;
			updateRedisHashField(getKey(), "discountShopPrice", this.discountShopPrice);
		}
	}

	public void addDiscountShopPrice(int value) {
		this.discountShopPrice += value;
		updateRedisHashField(getKey(), "discountShopPrice", this.discountShopPrice);
	}

	public byte getIsDiscountShopBuy() {
		return isDiscountShopBuy;
	}

	public void putIsDiscountShopBuy(byte isDiscountShopBuy) {
		if (this.isDiscountShopBuy != isDiscountShopBuy) {
			this.isDiscountShopBuy = isDiscountShopBuy;
			updateRedisHashField(getKey(), "isDiscountShopBuy", this.isDiscountShopBuy);
		}
	}

	public void addIsDiscountShopBuy(byte value) {
		this.isDiscountShopBuy += value;
		updateRedisHashField(getKey(), "isDiscountShopBuy", this.isDiscountShopBuy);
	}

	public int getBossFreeNum() {
		return bossFreeNum;
	}

	public void putBossFreeNum(int bossFreeNum) {
		if (this.bossFreeNum != bossFreeNum) {
			this.bossFreeNum = bossFreeNum;
			updateRedisHashField(getKey(), "bossFreeNum", this.bossFreeNum);
		}
	}

	public void addBossFreeNum(int value) {
		this.bossFreeNum += value;
		updateRedisHashField(getKey(), "bossFreeNum", this.bossFreeNum);
	}

	public int getBossBuyNum() {
		return bossBuyNum;
	}

	public void putBossBuyNum(int bossBuyNum) {
		if (this.bossBuyNum != bossBuyNum) {
			this.bossBuyNum = bossBuyNum;
			updateRedisHashField(getKey(), "bossBuyNum", this.bossBuyNum);
		}
	}

	public void addBossBuyNum(int value) {
		this.bossBuyNum += value;
		updateRedisHashField(getKey(), "bossBuyNum", this.bossBuyNum);
	}

	public int getBossAddPowerNum() {
		return bossAddPowerNum;
	}

	public void putBossAddPowerNum(int bossAddPowerNum) {
		if (this.bossAddPowerNum != bossAddPowerNum) {
			this.bossAddPowerNum = bossAddPowerNum;
			updateRedisHashField(getKey(), "bossAddPowerNum", this.bossAddPowerNum);
		}
	}

	public void addBossAddPowerNum(int value) {
		this.bossAddPowerNum += value;
		updateRedisHashField(getKey(), "bossAddPowerNum", this.bossAddPowerNum);
	}

}